home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / UI / Window.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  55.1 KB  |  2,058 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Window.cpp
  3.  
  4.     Contains:    Implementation of class ODWindow
  5.  
  6.     Owned by:    Chris Linn
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <9>      11/27/96    CSL        1385215: Changes for container app support
  13.          <8>     9/24/96    eeh        1315228: Verify part wrapper passed
  14.          <7>     9/18/96    CSL        1356527: Move docs on-screen if structure
  15.                                     rgn is off-screen (not just title bar).
  16.                                     1304227:  Don't send suspend/resume events
  17.                                     t to windows that haven't been Opened yet.
  18.          <6>     6/21/96    CSL        1356527: Doc windows are shown off-screen
  19.                                     if monitor configuration changes.
  20.          <5>     6/14/96    CSL        1316010: Document window disappears forever
  21.                                     on save if WindowShaded
  22.          <4>     5/24/96    jpa        1246074: Added missing SOM_CATCH_ALL's.
  23.          <2>     3/15/96    VL        1302780: Added GetFacetUnderPointForDrag so
  24.                                     that we can ignore selection when we try to
  25.                                     find the facet under mouse point.
  26.  
  27.     To Do:
  28.     
  29.     In Progress:
  30.         
  31. */
  32.  
  33. #define ODWindow_Class_Source
  34.  
  35.  
  36.  
  37. #ifndef _ALTPOINT_
  38. #include "AltPoint.h"            // Use C++ savvy XMPPoint and XMPRect
  39. #endif
  40.  
  41.  
  42. #ifndef SOM_ODWindow_xih
  43. #define VARIABLE_MACROS
  44. #include <Window.xih>
  45. #endif
  46.  
  47. #ifndef _PLFMDEF_
  48. #include "PlfmDef.h"
  49. #endif
  50.  
  51. #ifndef _TEMPOBJ_
  52. #include <TempObj.h>
  53. #endif
  54.  
  55. #ifndef SOM_ODStorageUnit_xh
  56. #include <StorageU.xh>
  57. #endif
  58.  
  59. #ifndef SOM_ODStorageSystem_xh
  60. #include <ODStor.xh>
  61. #endif
  62.  
  63. #ifndef SOM_ODDraft_xh
  64. #include <Draft.xh>
  65. #endif
  66.  
  67. #ifndef SOM_ODDocument_xh
  68. #include <Document.xh>
  69. #endif
  70.  
  71. #ifndef SOM_ODContainer_xh
  72. #include <ODCtr.xh>
  73. #endif
  74.  
  75. #ifndef SOM_ODSession_xh
  76. #include <ODSessn.xh>
  77. #endif
  78.  
  79. #ifndef SOM_ODPart_xh
  80. #include <Part.xh>
  81. #endif
  82.  
  83. #ifndef SOM_ODDispatcher_xh
  84. #include <Disptch.xh>
  85. #endif
  86.  
  87. #ifndef SOM_ODWindowState_xh
  88. #include <WinStat.xh>
  89. #endif
  90.  
  91. #ifndef SOM_ODArbitrator_xh
  92. #include <Arbitrat.xh>
  93. #endif
  94.  
  95. #ifndef SOM_ODFrame_xh
  96. #include <Frame.xh>
  97. #endif
  98.  
  99.  
  100. #ifndef SOM_ODFacetIterator_xh
  101. #include <FacetItr.xh>
  102. #endif
  103.  
  104. #ifndef SOM_ODFacet_xh
  105. #include <Facet.xh>
  106. #endif
  107.  
  108. #ifndef SOM_ODCanvas_xh
  109. #include <Canvas.xh>
  110. #endif
  111.  
  112. #ifndef SOM_ODShape_xh
  113. #include <Shape.xh>
  114. #endif
  115.  
  116. #ifndef SOM_ODTransform_xh
  117. #include <Trnsform.xh>
  118. #endif
  119.  
  120. #ifndef _ODUTILS_
  121. #include <ODUtils.h>
  122. #endif
  123.  
  124. #ifndef SOM_Module_OpenDoc_Foci_defined
  125. #include <Foci.xh>
  126. #endif
  127.  
  128. #ifndef _STDTYPIO_
  129. #include <StdTypIO.h>
  130. #endif
  131.  
  132. #ifndef _ITEXT_
  133. #include "IText.h"
  134. #endif
  135.  
  136. #ifndef __TOOLUTILS__
  137. #include <ToolUtils.h>
  138. #endif
  139.  
  140. #ifndef __RESOURCES__
  141. #include <Resources.h>
  142. #endif
  143.  
  144. #ifndef __OSUTILS__
  145. #include <OSUtils.h>    // SysBeep etc.
  146. #endif
  147.  
  148. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  149. #include <StdTypes.xh>
  150. #endif
  151.  
  152. #ifndef SOM_Module_OpenDoc_StdProps_defined
  153. #include <StdProps.xh>
  154. #endif
  155.  
  156. #ifndef _EXCEPT_
  157. #include "Except.h"
  158. #endif
  159.  
  160. #ifndef __OCESTANDARDMAIL__
  161. #include <OCEStandardMail.h>
  162. #endif
  163.  
  164. #ifndef __OCEERRORS__
  165. #include <OCEErrors.h>
  166. #endif
  167.  
  168. #ifndef SOM_ODMenuBar_xh
  169. #include <MenuBar.xh>
  170. #endif
  171.  
  172. #ifndef SOM_Module_OpenDoc_Commands_defined
  173. #include <CmdDefs.xh>
  174. #endif
  175.  
  176. #ifndef _PASCLSTR_
  177. #include "PasclStr.h"
  178. #endif
  179.  
  180. #ifndef _CONSTDEF_
  181. #include "ConstDef.h"
  182. #endif
  183.  
  184. #ifndef __GESTALTEQU__
  185. #include <GestaltEqu.h>
  186. #endif
  187.  
  188. #ifndef __DIALOGS__
  189. #include <Dialogs.h>
  190. #endif
  191.  
  192. #ifndef _ODDEBUG_
  193. #include "ODDebug.h"
  194. #endif
  195.  
  196. #ifndef _DOCUTILS_
  197. #include <DocUtils.h>
  198. #endif
  199.  
  200. #ifndef _STORUTIL_
  201. #include <StorUtil.h>
  202. #endif
  203.  
  204. #ifndef _ISOSTR_
  205. #include "ISOStr.h"
  206. #endif
  207.  
  208. #pragma segment ODWindow
  209.  
  210. #include "WindowB.cpp"    // Platform-independent methods, if any
  211.  
  212. #define ODDebugActivates 0
  213.  
  214. //==============================================================================
  215. // Constants
  216. //==============================================================================
  217.  
  218. // Check ErrorDef.idl before adding any new codes here, to make sure they're unique.
  219. const ODError kODErrInvalidPlatformWindow         = -29828;
  220. const ODError kODErrInvalidWindow                = -29827;
  221.  
  222. // TÇ: This error code was only being used in this file, and then only
  223. // for checking the _fPlatformWindow field of a window at the beginning of
  224. // methods.  It didn't seem to have anything to do with the api.
  225. // That is why I made it private to this file.
  226. // perhaps the error that should be thrown is kODErrObjectNotInitialized?
  227. // kODErrInvalidWindow falls into the same category.
  228.  
  229.  
  230. //==============================================================================
  231. // Types
  232. //==============================================================================
  233.  
  234. //=====================================================================================
  235. // ODWindow Methods
  236. //=====================================================================================
  237.  
  238.  
  239. //-------------------------------------------------------------------------------------
  240. // ODWindow: CommonInitWindow    
  241. //-------------------------------------------------------------------------------------
  242.  
  243. SOM_Scope void  SOMLINK ODWindowCommonInitWindow(ODWindow *somSelf, Environment *ev)
  244. {
  245.     ODWindowData *somThis = ODWindowGetData(somSelf);
  246.     ODWindowMethodDebug("ODWindow","CommonInitWindow");
  247.     
  248.     SOM_TRY
  249.  
  250.         _fSession = (ODSession*) _fDraft->GetDocument(ev)->GetContainer(ev)->GetStorageSystem(ev)->GetSession(ev);    
  251.         _fWindowState = _fSession->GetWindowState( ev );
  252.         _fSelectionFocus = _fSession->Tokenize(ev,kODSelectionFocus);
  253.     
  254.     SOM_CATCH_ALL
  255.     SOM_ENDTRY
  256. }
  257.  
  258.  
  259. //-------------------------------------------------------------------------------------
  260. // ODWindow: InitWindow                
  261. //-------------------------------------------------------------------------------------
  262.  
  263. SOM_Scope void  SOMLINK ODWindowInitWindow (ODWindow *somSelf, Environment *ev,
  264.         ODPlatformWindow    platformWindow, 
  265.         ODType                frameType,
  266.         ODBoolean            isRootWindow,
  267.         ODBoolean            isResizable,
  268.         ODBoolean            isFloating,
  269.         ODBoolean            shouldSave,
  270.         ODBoolean            shouldDispose,
  271.         ODPart*                rootPart,
  272.         ODTypeToken            viewType,
  273.         ODTypeToken            presentation,
  274.         ODFrame*            sourceFrame)
  275. {
  276.     ODWindowData *somThis = ODWindowGetData(somSelf);
  277.     ODWindowMethodDebug("ODWindow","InitWindow");
  278.  
  279.     SOM_TRY
  280.     
  281.         /* Moved from somInit. SOM itself sets fields to zero
  282.         _fPlatformWindow = kODNULL;
  283.         _fRootFacet = kODNULL;
  284.         _fSourceFrame = kODNULL;
  285.         _fSession = kODNULL;
  286.         _fIsRootWindow = kODTrue;
  287.         _fShouldSave = kODTrue;
  288.         _fIsResizable = kODFalse;
  289.         _fIsFloating = kODFalse;
  290.         _fWasVisible = kODFalse;
  291.         _fShouldShowLinks = kODFalse;
  292.         _fWindowState = kODNULL;
  293.         
  294.         _fStorageUnit = kODNULL;
  295.         _fIsDirty = kODFalse;
  296.         _fDraft = kODNULL;
  297.         
  298.         _fShouldAdjustOnOpen = kODFalse;
  299.         _fInBackground = kODFalse;
  300.         _fIsActive = kODFalse;
  301.         _fSelectionFocus = 0;
  302.         */
  303.         _fShouldDispose    = shouldDispose;    
  304.         
  305.         somSelf->InitRefCntObject(ev);
  306.  
  307. #if ODDebug
  308.         if (shouldSave && ODISOStrEqual(frameType, kODNonPersistentFrameObject)) 
  309.             WARN("InitWindow: shouldSave is TRUE, but root frame is nonpersistent ");
  310.  
  311. #endif
  312.         WASSERT_IS_PART_WRAPPER( ev, rootPart );
  313.         
  314.         _fPlatformWindow = platformWindow;
  315.         _fIsRootWindow    = isRootWindow;
  316.         _fIsResizable    = isResizable;
  317.         _fIsFloating    = isFloating;
  318.         if (sourceFrame)
  319.             sourceFrame->Acquire(ev);
  320.         _fSourceFrame    = sourceFrame;
  321.         _fDraft            = rootPart->GetStorageUnit(ev)->GetDraft(ev);
  322.         _fDraft->Acquire(ev);
  323.         if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
  324.         {
  325.             shouldSave = kODFalse;
  326.             frameType = kODNonPersistentFrameObject;
  327.         }
  328.     
  329.         _fShouldSave     = shouldSave;
  330.     
  331.         somSelf->CommonInitWindow(ev);
  332.         
  333.         somSelf->CreateRootFrame(ev, frameType, viewType, presentation, rootPart);
  334.     
  335.         _fIsDirty = kODTrue;
  336.         _fShouldAdjustOnOpen = kODTrue;
  337.     
  338.     SOM_CATCH_ALL
  339.     SOM_ENDTRY
  340. }
  341. //-------------------------------------------------------------------------------------
  342. // ODWindow: InitWindowForFrame                
  343. //-------------------------------------------------------------------------------------
  344.  
  345. SOM_Scope void  SOMLINK ODWindowInitWindowForFrame (ODWindow *somSelf, Environment *ev,
  346.         ODPlatformWindow    platformWindow, 
  347.         ODFrame*            frame,
  348.         ODBoolean            isRootWindow,
  349.         ODBoolean            isResizable,
  350.         ODBoolean            isFloating,
  351.         ODBoolean            shouldSave,
  352.         ODBoolean            shouldDispose,
  353.         ODFrame*            sourceFrame)
  354. {
  355.     ODWindowData *somThis = ODWindowGetData(somSelf);
  356.     ODWindowMethodDebug("ODWindow","InitWindow");
  357.     
  358.     SOM_TRY
  359.     
  360.         ASSERT(frame != kODNULL, kODErrInvalidFrame);
  361.             
  362.         /* Moved from somInit. SOM itself sets fields to zero
  363.         _fPlatformWindow = kODNULL;
  364.         _fRootFacet = kODNULL;
  365.         _fSourceFrame = kODNULL;
  366.         _fSession = kODNULL;
  367.         _fIsRootWindow = kODTrue;
  368.         _fShouldSave = kODTrue;
  369.         _fIsResizable = kODFalse;
  370.         _fIsFloating = kODFalse;
  371.         _fWasVisible = kODFalse;
  372.         _fShouldShowLinks = kODFalse;
  373.         _fWindowState = kODNULL;
  374.         
  375.         _fStorageUnit = kODNULL;
  376.         _fIsDirty = kODFalse;
  377.         _fDraft = kODNULL;
  378.         
  379.         _fShouldAdjustOnOpen = kODFalse;
  380.         _fInBackground = kODFalse;
  381.         _fSelectionFocus = 0;
  382.         */
  383.         _fShouldDispose    = shouldDispose;    
  384.  
  385.         somSelf->InitRefCntObject(ev);
  386.  
  387. #if ODDebug
  388.         if (shouldSave && (frame->GetStorageUnit(ev) == kODNULL))
  389.             WARN("InitWindowForFrame: shouldSave is TRUE, but root frame is nonpersistent ");
  390.  
  391. #endif
  392.  
  393.         _fPlatformWindow = platformWindow;
  394.         _fIsRootWindow    = isRootWindow;
  395.         _fIsResizable    = isResizable;
  396.         _fIsFloating    = isFloating;
  397.         if (sourceFrame)
  398.             sourceFrame->Acquire(ev);
  399.         _fSourceFrame    = sourceFrame;
  400.         { 
  401.             TempODPart part = frame->AcquirePart(ev);
  402.             _fDraft            = part->GetStorageUnit(ev)->GetDraft(ev);
  403.             _fDraft->Acquire(ev);
  404.         }
  405.     
  406.         if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
  407.             shouldSave = kODFalse;
  408.     
  409.         _fShouldSave    = shouldSave;
  410.     
  411.         somSelf->CommonInitWindow(ev);
  412.         
  413.         if (frame)
  414.         {
  415.             frame->Acquire(ev);
  416.             frame->SetWindow(ev, somSelf);
  417.         }
  418.         _fRootFrame = frame;
  419.     
  420.         _fIsDirty = kODFalse;
  421.         _fShouldAdjustOnOpen = kODFalse;
  422.         
  423.         ODStorageUnit* frameSU = frame->GetStorageUnit(ev);
  424.         if ((frameSU != kODNULL) && (_fDraft != kODNULL))
  425.         {
  426.             ODID windowPropsID = ODGetStrongSURefProp(ev, frameSU, kODPropWindowProperties, kODStrongStorageUnitRef);
  427.             if (windowPropsID != kODNULLID)
  428.             {
  429.                 _fStorageUnit = _fDraft->AcquireStorageUnit(ev, windowPropsID);
  430.             }
  431.         }
  432.  
  433.     SOM_CATCH_ALL
  434.     SOM_ENDTRY
  435. }
  436.  
  437. //-------------------------------------------------------------------------------------
  438. // ODWindow: Purge
  439. //
  440. // Description
  441. //-------------------------------------------------------------------------------------
  442.         
  443. SOM_Scope ODSize     SOMLINK ODWindowPurge(ODWindow *somSelf, Environment *ev,
  444.         ODSize size)
  445. {
  446.     ODWindowData *somThis = ODWindowGetData(somSelf);
  447.     ODWindowMethodDebug("ODWindow","Purge");
  448.     
  449.     ODSize purgeSize = 0;
  450.     
  451.     SOM_TRY
  452.     
  453.         purgeSize = parent_Purge(somSelf, ev, size);
  454.         
  455.     SOM_CATCH_ALL
  456.         WARN("Error %ld trying to purge in ODWindowPurge",ErrorCode());
  457.         SetErrorCode(kODNoError);        // Eat the exception; Purge should not 
  458.                                         // propagate it because clients function
  459.                                         // fine whether memory was purged or not.
  460.     SOM_ENDTRY
  461.  
  462.     return purgeSize;
  463. }
  464.  
  465. //-------------------------------------------------------------------------------------
  466. // ODWindow: Release
  467. //
  468. // Description
  469. //-------------------------------------------------------------------------------------
  470.         
  471. SOM_Scope void     SOMLINK ODWindowRelease(ODWindow *somSelf, Environment *ev)
  472. {
  473.     ODWindowData *somThis = ODWindowGetData(somSelf);
  474.     ODWindowMethodDebug("ODWindow","Release");
  475.     
  476.     SOM_TRY
  477.  
  478.         parent_Release(somSelf, ev); 
  479.         if (somSelf->GetRefCount(ev) == 0) 
  480.             _fWindowState->ReleaseWindow(ev,somSelf);
  481.  
  482.     SOM_CATCH_ALL
  483.     SOM_ENDTRY
  484. }
  485.  
  486. //-------------------------------------------------------------------------------------
  487. // ODWindow: ~ODWindow                
  488. //
  489. // Description
  490. //-------------------------------------------------------------------------------------
  491.  
  492. SOM_Scope void  SOMLINK ODWindowsomUninit (ODWindow *somSelf)
  493. {
  494.     ODWindowData *somThis = ODWindowGetData(somSelf);
  495.     ODWindowMethodDebug("ODWindow","somUninit");
  496.  
  497.     Environment* ev = somGetGlobalEnvironment();
  498.     //    • Get rid of our window
  499.     if (_fPlatformWindow && _fShouldDispose)
  500.     {
  501.         if (((WindowRecord*)_fPlatformWindow)->windowKind == dialogKind)
  502.             DisposeDialog(_fPlatformWindow);
  503.         else
  504.             DisposeWindow(_fPlatformWindow);
  505.         _fPlatformWindow = kODNULL;
  506.     }
  507.     
  508.     // Storage Unit must be released before draft    
  509.     ODSafeReleaseObject(_fStorageUnit);    
  510.     ODSafeReleaseObject(_fDraft);        
  511.     ODSafeReleaseObject(_fRootFrame);    
  512.     ODSafeReleaseObject(_fSourceFrame); 
  513. }    //     SOMLINK ODWindowsomUninit
  514.  
  515. //-------------------------------------------------------------------------------------
  516. // ODWindow: GetPlatformWindow
  517. //
  518. // Description
  519. //-------------------------------------------------------------------------------------
  520.  
  521. SOM_Scope ODPlatformWindow      SOMLINK ODWindowGetPlatformWindow(ODWindow *somSelf, Environment *ev)
  522. {
  523.     ODWindowData *somThis = ODWindowGetData(somSelf);
  524.     ODWindowMethodDebug("ODWindow","GetPlatformWindow");
  525.  
  526.     return _fPlatformWindow;
  527. }
  528.  
  529. //-------------------------------------------------------------------------------------
  530. // ODWindow: AcquireSourceFrame
  531. //
  532. // Description
  533. //-------------------------------------------------------------------------------------
  534.  
  535. SOM_Scope ODFrame*     SOMLINK ODWindowAcquireSourceFrame(ODWindow *somSelf, Environment *ev) 
  536. {
  537.     ODWindowData *somThis = ODWindowGetData(somSelf);
  538.     ODWindowMethodDebug("ODWindow","AcquireSourceFrame");
  539.     
  540.     SOM_TRY
  541.     
  542.     if (_fSourceFrame)
  543.         _fSourceFrame->Acquire(ev);
  544.  
  545.      SOM_CATCH_ALL
  546.     SOM_ENDTRY
  547.     return _fSourceFrame; 
  548. }
  549.  
  550. //-------------------------------------------------------------------------------------
  551. // ODWindow: SetSourceFrame
  552. //
  553. // Description
  554. //-------------------------------------------------------------------------------------
  555.  
  556. SOM_Scope void     SOMLINK ODWindowSetSourceFrame(ODWindow *somSelf, Environment *ev, 
  557.                                                 ODFrame* frame) 
  558. {
  559.     ODWindowData *somThis = ODWindowGetData(somSelf);
  560.     ODWindowMethodDebug("ODWindow","AcquireSourceFrame");
  561.     
  562.     SOM_TRY
  563.  
  564.         if (frame)
  565.             frame->Acquire(ev);
  566.         if (_fSourceFrame)
  567.             _fSourceFrame->Release(ev);
  568.      
  569.         _fSourceFrame = frame; 
  570.     
  571.     SOM_CATCH_ALL
  572.     SOM_ENDTRY
  573. }
  574.  
  575. //-------------------------------------------------------------------------------------
  576. // ODWindow: GetRootFrame
  577. //
  578. // Description
  579. //-------------------------------------------------------------------------------------
  580.  
  581. SOM_Scope ODFrame*  SOMLINK ODWindowGetRootFrame(ODWindow *somSelf, Environment *ev) 
  582. {
  583.     ODWindowData *somThis = ODWindowGetData(somSelf);
  584.     ODWindowMethodDebug("ODWindow","GetRootFrame");
  585.  
  586.     return _fRootFrame; 
  587. }
  588.         
  589. //-------------------------------------------------------------------------------------
  590. // ODWindow: GetRootFacet
  591. //
  592. // Description
  593. //-------------------------------------------------------------------------------------
  594.  
  595. SOM_Scope ODFacet*  SOMLINK ODWindowGetRootFacet(ODWindow *somSelf, Environment *ev)
  596. {
  597.     ODWindowData *somThis = ODWindowGetData(somSelf);
  598.     ODWindowMethodDebug("ODWindow","GetRootFacet");
  599.  
  600.     return _fRootFacet;
  601. }    
  602.     
  603. //-------------------------------------------------------------------------------------
  604. // ODWindow: CreateRootFrame
  605. // PRIVATE
  606. //
  607. // Description
  608. //-------------------------------------------------------------------------------------
  609.  
  610. SOM_Scope void  SOMLINK ODWindowCreateRootFrame(ODWindow *somSelf, Environment *ev,
  611.         ODType        frameType,
  612.         ODTypeToken    viewType,
  613.         ODTypeToken    presentation,
  614.         ODPart* rootPart)
  615. {
  616.     ODWindowData *somThis = ODWindowGetData(somSelf);
  617.     ODWindowMethodDebug("ODWindow","CreateRootFrame");
  618.  
  619.     ODShape* newShape = kODNULL;ODVolatile(newShape);
  620.     
  621.     SOM_TRY
  622.     
  623.         WASSERT_IS_PART_WRAPPER( ev, rootPart );
  624.  
  625.         if (_fPlatformWindow)
  626.         {
  627.             Rect frameShape = _fPlatformWindow->portRect;
  628.             
  629.             TRY
  630.     
  631.                 newShape = new ODShape; // Can't Use factory method because no frame is available yet
  632.                 THROW_IF_NULL(newShape);
  633.                 newShape->InitShape(ev);
  634.                 
  635.             CATCH_ALL
  636.                 ODDeleteObject(newShape); newShape = kODNULL; // must delete before InitShape returns
  637.                 RERAISE;
  638.             ENDTRY
  639.     
  640.             TempODShape tempShape = newShape;    // ensures it's released
  641.             
  642.             ODRect r = _fPlatformWindow->portRect;
  643.             newShape->SetRectangle(ev,&r);
  644.             _fRootFrame = _fDraft->CreateFrame(ev, frameType, (ODFrame*)kODNULL,
  645.                                         newShape, (ODCanvas*)kODNULL,
  646.                                         rootPart, viewType, presentation,
  647.                                         kODFalse,    // isSubframe
  648.                                         kODFalse);    // isOverlaid
  649.             _fRootFrame->SetWindow(ev, somSelf);
  650.         
  651.             if (rootPart && _fSourceFrame)
  652.                 rootPart->AttachSourceFrame(ev, _fRootFrame, _fSourceFrame);
  653.         }
  654.         _fIsDirty = kODTrue;
  655.  
  656.     SOM_CATCH_ALL
  657.     SOM_ENDTRY
  658. }    // CreateRootFrame()
  659.  
  660. //-------------------------------------------------------------------------------------
  661. // ODWindow: CreateRootFacet
  662. //-------------------------------------------------------------------------------------
  663.  
  664. SOM_Scope void  SOMLINK ODWindowCreateRootFacet(ODWindow *somSelf, Environment *ev)
  665. {
  666.     ODWindowData *somThis = ODWindowGetData(somSelf);
  667.     ODWindowMethodDebug("ODWindow","CreateRootFacet");
  668.  
  669.     ODShape* frameShape = kODNULL;
  670.     ODShape* clipShape = kODNULL;
  671.     
  672.     SOM_TRY
  673.     
  674.         frameShape = _fRootFrame->AcquireFrameShape(ev, kODNULL);
  675.         clipShape = frameShape->Copy(ev);
  676.         ODReleaseObject(ev, frameShape);
  677.     
  678.         ODTransform* externalTransform = _fRootFrame->CreateTransform(ev); 
  679.         
  680.         ODCanvas* rootCanvas = _fWindowState->CreateCanvas(ev, kODQuickDraw,
  681.                                 (ODPlatformCanvas) _fPlatformWindow,
  682.                                 kODTrue,        // isDynamic
  683.                                 kODFalse);        // isOffscreen
  684.     
  685.         _fRootFacet = _fWindowState->CreateFacet(ev, _fRootFrame, clipShape, externalTransform, rootCanvas, kODNULL);
  686.         ODReleaseObject(ev, clipShape);
  687.         ODReleaseObject(ev, externalTransform);
  688.         
  689.         _fRootFrame->FacetAdded(ev,_fRootFacet);
  690.         _fIsDirty = kODTrue;
  691.         
  692.     SOM_CATCH_ALL
  693.     SOM_ENDTRY
  694. }
  695.  
  696. //-------------------------------------------------------------------------------------
  697. // ODWindow: AdjustWindowShape
  698. //
  699. // Description
  700. //-------------------------------------------------------------------------------------
  701.  
  702. SOM_Scope void  SOMLINK ODWindowAdjustWindowShape (ODWindow *somSelf, Environment *ev)
  703. {
  704.     ODWindowData *somThis = ODWindowGetData(somSelf);
  705.     ODWindowMethodDebug("ODWindow","AdjustWindowShape");
  706.     
  707.     SOM_TRY
  708.  
  709.         if (_fPlatformWindow)
  710.         {
  711.             Rect contentRect = _fPlatformWindow->portRect;
  712.             Rect growRect = contentRect;
  713.             growRect.left = growRect.right - 15;
  714.             growRect.top = growRect.bottom - 15;
  715.             
  716.             RgnHandle contentRgn = ODNewRgn();
  717.             RgnHandle growRgn = ODNewRgn();
  718.             RectRgn(contentRgn,&contentRect);
  719.             RectRgn(growRgn,&growRect);
  720.                     
  721.             if (_fIsResizable)
  722.             DiffRgn(contentRgn,growRgn,contentRgn);
  723.             ODDisposeHandle((Handle)growRgn);
  724.     
  725.             SetPort(_fPlatformWindow);
  726.             // InvalRgn(contentRgn);
  727.                     
  728.             ODShape* windowShape =_fRootFrame->CreateShape(ev);
  729.             windowShape->SetPlatformShape(ev,kODQuickDraw, (ODPlatformShape)contentRgn);
  730.             ODShape* tempShape = kODNULL;
  731.             tempShape = windowShape->Copy(ev);
  732.             _fRootFacet->GetFrame(ev)->ChangeFrameShape(ev, windowShape, kODNULL);
  733.             _fRootFacet->ChangeGeometry(ev, tempShape, kODNULL, kODNULL);
  734.             ODReleaseObject(ev, windowShape);
  735.             ODReleaseObject(ev, tempShape);
  736.         }
  737.         _fIsDirty = kODTrue;
  738.  
  739.     SOM_CATCH_ALL
  740.     SOM_ENDTRY
  741. }    // AdjustWindowShape
  742.  
  743.  
  744. //-------------------------------------------------------------------------------------
  745. // ODWindow: Open
  746. //
  747. // Description
  748. //-------------------------------------------------------------------------------------
  749.  
  750.  
  751. SOM_Scope void  SOMLINK ODWindowOpen (ODWindow *somSelf, Environment *ev)
  752. {
  753.     ODWindowData *somThis = ODWindowGetData(somSelf);
  754.     ODWindowMethodDebug("ODWindow","Open");
  755.     
  756.     SOM_TRY
  757.  
  758.         if (_fRootFacet == kODNULL)
  759.         {
  760.             somSelf->CreateRootFacet(ev);
  761.             if ( _fShouldAdjustOnOpen )
  762.                 somSelf->AdjustWindowShape(ev);
  763.             _fIsDirty = kODTrue;
  764.         }
  765.     
  766.     SOM_CATCH_ALL
  767.     SOM_ENDTRY
  768. }
  769.  
  770. //-------------------------------------------------------------------------------------
  771. // ODWindow: Close
  772. //
  773. // Description
  774. //-------------------------------------------------------------------------------------
  775.  
  776.  
  777. SOM_Scope void  SOMLINK ODWindowClose(ODWindow *somSelf, Environment *ev)
  778. {
  779.     ODWindowData *somThis = ODWindowGetData(somSelf);
  780.     ODWindowMethodDebug("ODWindow","Close");
  781.  
  782.     SOM_TRY
  783.     
  784.         somSelf->Hide(ev);
  785.         _fWindowState->RemoveWindow(ev,somSelf);
  786.     
  787.         if ( _fRootFrame )
  788.         {
  789.             if ( _fRootFacet )
  790.             {
  791.                 _fRootFrame->FacetRemoved(ev,_fRootFacet);
  792.                 _fSession->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  793.                 
  794.                 ODCanvas* rootCanvas = _fRootFacet->GetCanvas(ev); // DMc - new
  795.                 ODDeleteObject(rootCanvas); // DMc - new
  796.                 ODDeleteObject(_fRootFacet);
  797.             }
  798.     
  799.             _fRootFrame->Close(ev);
  800.             _fRootFrame = kODNULL;
  801.         }
  802.         
  803.         ODReleaseObject(ev, _fSourceFrame);
  804.         _fIsDirty = kODTrue;
  805.         somSelf->Release(ev);
  806.  
  807.     SOM_CATCH_ALL
  808.     SOM_ENDTRY
  809.     
  810. }    // Close()
  811.  
  812. //-------------------------------------------------------------------------------------
  813. // ODWindow: CloseAndRemove
  814. //
  815. // Description
  816. //-------------------------------------------------------------------------------------
  817.  
  818.  
  819. SOM_Scope void  SOMLINK ODWindowCloseAndRemove(ODWindow *somSelf, Environment *ev)
  820. {
  821.     ODWindowData *somThis = ODWindowGetData(somSelf);
  822.     ODWindowMethodDebug("ODWindow","CloseAndRemove");
  823.     
  824.     SOM_TRY
  825.     
  826.         if (_fPlatformWindow)
  827.         {
  828.             somSelf->Hide(ev);
  829.             _fWindowState->RemoveWindow(ev,somSelf);
  830.         
  831.             if ( _fRootFrame )
  832.             {
  833.                 if ( _fRootFacet )
  834.                 {
  835.                     _fRootFrame->FacetRemoved(ev,_fRootFacet);
  836.                     _fSession->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  837.                     
  838.                     ODCanvas* rootCanvas = _fRootFacet->GetCanvas(ev); // DMc - new
  839.                     ODDeleteObject(rootCanvas); // DMc - new
  840.                     ODDeleteObject(_fRootFacet);
  841.                 }
  842.         
  843.                 if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
  844.                 {
  845.                     _fRootFrame->Close(ev);
  846.                     _fRootFrame = kODNULL;
  847.                 }
  848.                 else
  849.                 {
  850.                     _fRootFrame->Remove(ev);
  851.                     _fRootFrame = kODNULL;
  852.                 }
  853.             }
  854.             
  855.             ODReleaseObject(ev, _fSourceFrame);
  856.             somSelf->Release(ev);
  857.             _fIsDirty = kODTrue;
  858.         }
  859.  
  860.     SOM_CATCH_ALL
  861.     SOM_ENDTRY
  862.  
  863. }    
  864.  
  865.  
  866.  
  867. //-------------------------------------------------------------------------------------
  868. // ODWindow: HandleActivateEvent
  869. //
  870. // Description
  871. //-------------------------------------------------------------------------------------
  872.  
  873. static void ODDrawGrowIcon(ODPlatformWindow window)
  874. {
  875.     GrafPtr    savePort;
  876.         
  877.     GetPort(&savePort);
  878.     SetPort(window);
  879.     Rect r = window->portRect;
  880.     r.left = r.right  - 15;
  881.     r.top  = r.bottom - 15;
  882.     RgnHandle    oldClip = kODNULL; ODVolatile(oldClip);
  883.     
  884.     TRY
  885.         oldClip = ODNewRgn();
  886.  
  887.         GetClip(oldClip);
  888.         ClipRect(&r);
  889.         DrawGrowIcon(window);
  890.         SetClip(oldClip);
  891.         
  892.     CATCH_ALL
  893.         // Don't Reraise. Since this gets called when putting up
  894.         // the low memory alert calls DeactivateFrontWindows #1280629
  895.     ENDTRY
  896.         
  897.     ODDisposeHandle((Handle)oldClip);
  898.     SetPort(savePort);
  899. }
  900.  
  901. // Code to keep windows from being activated off-screen.
  902. // Set OD_SLAM_WINDOWS to 1 to force windows on-screen.
  903. // Set OD_SLAM_WINDOWS to 0 to just give a debug warning.
  904. #if ODDebug
  905.     // Validate windows in the debug build:
  906.     #define OD_VALIDATE_WINDOW(w) ValidateWindow(w)
  907.     #define OD_SLAM_WINDOWS 1
  908. #else /* ODDebug */
  909.     // Currently, these settings are the same as the debug ones
  910.     #define OD_VALIDATE_WINDOW(w) ValidateWindow(w)
  911.     #define OD_SLAM_WINDOWS 1
  912. #endif /* ODDebug */
  913.  
  914. static void ValidateWindow( ODPlatformWindow newWindow )
  915. {
  916.     WindowPeek wp = (WindowPeek)newWindow;
  917.  
  918.     if ( wp->visible && wp->hilited )    // Test only visible, active windows
  919.     {
  920.         Rect rectToCheck = (**wp->strucRgn).rgnBBox;
  921.         // The next line, if uncommented, forces that the titlebar
  922.         // be on-screen.  I decided to relax the requirement to allow
  923.         // any part of the window so that windows that cover the full
  924.         // screen are possible.
  925.  
  926.         /* rectToCheck.bottom = (**wp->contRgn).rgnBBox.top; */
  927.  
  928.         InsetRect( &rectToCheck, 4, 4 );    // At least 4 pixels must be on-screen
  929.         if ( !EmptyRect( &rectToCheck ))
  930.         {
  931.             static RgnHandle rgn = kODNULL;            
  932.             if ( rgn == kODNULL )
  933.                 rgn = ODNewRgn();
  934.  
  935.             RectRgn( rgn, &rectToCheck );
  936.             SectRgn( GetGrayRgn(), rgn, rgn );
  937.             if ( EmptyRgn( rgn ))
  938.             {
  939. #if OD_SLAM_WINDOWS
  940.                 WARN( "This window is not on-screen. It will be moved." );
  941.                 
  942.                 // Place the window in the upper-left corner, just under the menubar
  943.                 short titleHeight = (**wp->contRgn).rgnBBox.top - (**wp->strucRgn).rgnBBox.top;
  944.                 MoveWindow( newWindow, 2, LMGetMBarHeight() + titleHeight + 1, false );
  945. #else
  946.                 WARN( "This window is not on-screen." );
  947. #endif
  948.             }
  949.             else
  950.                 SetRectRgn( rgn, 0, 0, 0, 0 );
  951.         }
  952.     }
  953.     // Note: The region is not disposed--it's static so we can use it
  954.     // next time instead of doing a relatively expensive allocation. We
  955.     // depend on the Process Manager to clean up when the process terminates.
  956. }
  957.  
  958. SOM_Scope void  SOMLINK ODWindowHandleActivateEvent (ODWindow *somSelf, Environment *ev,
  959.         ODEventData* theEvent)
  960. {
  961.     ODWindowData *somThis = ODWindowGetData(somSelf);
  962.     ODWindowMethodDebug("ODWindow","HandleActivateEvent");
  963.  
  964.     ODFrame* frame = kODNULL;
  965.     ODFacetIterator* t = kODNULL; ODVolatile(t);
  966.     
  967.     SOM_TRY
  968.  
  969.         ODBoolean activeState = ( theEvent->modifiers & activeFlag != 0 );
  970.  
  971.         if ( activeState )
  972.             OD_VALIDATE_WINDOW( (WindowPtr)theEvent->message );
  973.  
  974.         ::HiliteWindow( _fPlatformWindow, activeState );
  975.         
  976.         if ( _fRootFacet != kODNULL )
  977.         {
  978.             t = _fRootFacet->CreateFacetIterator(ev,
  979.                                     kODBottomUp, kODBackToFront);
  980.             
  981.             for (ODFacet* facet = t->First(ev); t->IsNotComplete(ev); facet = t->Next(ev))
  982.             {
  983.                 if (facet)
  984.                 {
  985.                     TRY{
  986.                         frame = facet->GetFrame(ev);
  987.                         TempODPart part = frame->AcquirePart(ev); // -- TÇ tempobj'd
  988.                         if ((ODPart*)part)
  989.                             part->HandleEvent(ev,theEvent, frame, facet, kODNULL);
  990.                     }CATCH_ALL{
  991.                         // ignore exception
  992.                     }ENDTRY
  993.                 }
  994.             }
  995.             ODDeleteObject(t);
  996.         }
  997.         else
  998.         {
  999.             WARN( "Can’t activate--This window has no root facet." );
  1000.         }
  1001.         if (somSelf->IsResizable(ev))
  1002.             ODDrawGrowIcon(_fPlatformWindow);
  1003.  
  1004.     SOM_CATCH_ALL
  1005.     
  1006.         ODDeleteObject(t);
  1007.         
  1008.     SOM_ENDTRY
  1009. }
  1010.     
  1011. //-------------------------------------------------------------------------------------
  1012. // ODWindow: HandleUpdateEvent
  1013. //
  1014. // Description
  1015. //-------------------------------------------------------------------------------------
  1016.  
  1017. SOM_Scope void  SOMLINK ODWindowHandleUpdateEvent (ODWindow *somSelf, Environment *ev,
  1018.         ODEventData* theEvent)
  1019. {
  1020.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1021.     ODWindowMethodDebug("ODWindow","HandleUpdateEvent");
  1022.  
  1023.     ODUnused(theEvent);
  1024.     
  1025.     SOM_TRY
  1026.         somSelf->Update(ev);
  1027.     SOM_CATCH_ALL
  1028.     SOM_ENDTRY
  1029. }
  1030.  
  1031. //-------------------------------------------------------------------------------------
  1032. // ODWindow: Update
  1033. //
  1034. // Description
  1035. //-------------------------------------------------------------------------------------
  1036.  
  1037. SOM_Scope void  SOMLINK ODWindowUpdate(ODWindow *somSelf, Environment *ev)
  1038. {
  1039.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1040.     ODWindowMethodDebug("ODWindow","Update");
  1041.     
  1042.     SOM_TRY
  1043.  
  1044.         if (_fPlatformWindow)
  1045.         {
  1046.                 // #1248624 Failure handling should be further improved, but this should prevent 
  1047.                 // the infinite dialog problem
  1048.             TRY    
  1049.                 GrafPtr    savePort;
  1050.         
  1051.                 GetPort(&savePort);
  1052.                 somSelf->PrepareCanvas(ev);
  1053.                 
  1054.                 TempODFrame activeFrame 
  1055.                     = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev,_fSelectionFocus);
  1056.                 BeginUpdate(_fPlatformWindow);                    // this sets up the visRgn
  1057.                 
  1058.                 if (!EmptyRgn(_fPlatformWindow->visRgn))            // draw if updating needs to be done 
  1059.                 {
  1060.                     // Let the part decide
  1061.                     // EraseRgn (_fPlatformWindow->visRgn);
  1062.                     
  1063.                     {
  1064.                         ODFacet* rootFacet = _fRootFacet;
  1065.             
  1066.                         RgnHandle updateRgn = ODNewRgn();
  1067.                         CopyRgn(_fPlatformWindow->visRgn, updateRgn);
  1068.                         TempODShape updateShape = rootFacet->CreateShape(ev);
  1069.                         updateShape->SetPlatformShape(ev,kODQuickDraw, updateRgn);
  1070.                         TempODTransform xform = rootFacet->AcquireWindowFrameTransform(ev, kODNULL);
  1071.                         updateShape->InverseTransform(ev, xform);
  1072.                         rootFacet->Update(ev, updateShape, kODNULL);
  1073.                     }
  1074.                     // • Focus back on the window so that everything gets reset
  1075.                     somSelf->PrepareCanvas(ev);
  1076.         
  1077.                     // • After everything is back in shape we need to get the grow icon drawn
  1078.                     if (somSelf->IsResizable(ev))
  1079.                         ODDrawGrowIcon(_fPlatformWindow);
  1080.                 }
  1081.                 EndUpdate(_fPlatformWindow);
  1082.                 somSelf->DrawActiveBorder(ev,activeFrame);
  1083.                 SetPort(savePort);
  1084.                 
  1085.             CATCH_ALL
  1086.                 EndUpdate(_fPlatformWindow);
  1087.             ENDTRY
  1088.         }    
  1089.         _fIsDirty = kODTrue;
  1090.     
  1091.     SOM_CATCH_ALL
  1092.     SOM_ENDTRY
  1093. }    //  SOMLINK ODWindowUpdate
  1094.  
  1095. //-------------------------------------------------------------------------------------
  1096. // ODWindow: DrawActiveBorder
  1097. //
  1098. // Description
  1099. //-------------------------------------------------------------------------------------
  1100.  
  1101. SOM_Scope void  SOMLINK ODWindowDrawActiveBorder(ODWindow *somSelf, Environment *ev, ODFrame* frame)
  1102. {
  1103.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1104.     ODWindowMethodDebug("ODWindow","DrawActiveBorder");
  1105.  
  1106. // !!! needs to draw border for all facets of active frame
  1107. // Don't draw in background. Also need to invalidate
  1108.  
  1109.     SOM_TRY
  1110.  
  1111.         if ( !_fInBackground && frame && (frame != _fRootFrame) )
  1112.         {
  1113.             frame->DrawActiveBorder(ev);
  1114.         }
  1115.         
  1116.     SOM_CATCH_ALL
  1117.     SOM_ENDTRY
  1118. }
  1119.  
  1120. //-------------------------------------------------------------------------------------
  1121. // ODWindow: PrepareCanvas
  1122. //
  1123. // Description
  1124. //-------------------------------------------------------------------------------------
  1125.  
  1126. SOM_Scope void  SOMLINK ODWindowPrepareCanvas(ODWindow *somSelf, Environment *ev)
  1127. {
  1128.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1129.     ODWindowMethodDebug("ODWindow","PrepareCanvas");
  1130.     
  1131.     SOM_TRY
  1132.  
  1133.         if (_fPlatformWindow)
  1134.         {
  1135.             SetPort (_fPlatformWindow);
  1136.             SetOrigin(0,0);
  1137.             ClipRect (&_fPlatformWindow->portRect);
  1138.         }
  1139.         else
  1140.             ClipRect (&ODQDGlobals.thePort->portRect);
  1141.  
  1142.     SOM_CATCH_ALL
  1143.     SOM_ENDTRY
  1144. }
  1145.  
  1146. //-------------------------------------------------------------------------------------
  1147. // ODWindow: IsResizable
  1148. //
  1149. // Description
  1150. //-------------------------------------------------------------------------------------
  1151.  
  1152. SOM_Scope ODBoolean  SOMLINK ODWindowIsResizable(ODWindow *somSelf, Environment *ev)
  1153. {
  1154.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1155.     ODWindowMethodDebug("ODWindow","IsResizable");
  1156.  
  1157.     return _fIsResizable;
  1158. }
  1159.  
  1160. //-------------------------------------------------------------------------------------
  1161. // ODWindow: IsFloating
  1162. //
  1163. // Description
  1164. //-------------------------------------------------------------------------------------
  1165.  
  1166. SOM_Scope ODBoolean  SOMLINK ODWindowIsFloating(ODWindow *somSelf, Environment *ev)
  1167. {
  1168.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1169.     ODWindowMethodDebug("ODWindow","IsFloating");
  1170.  
  1171.     return _fIsFloating;
  1172. }
  1173.  
  1174. //-------------------------------------------------------------------------------------
  1175. // ODWindow: IsRootWindow
  1176. //
  1177. // Description
  1178. //-------------------------------------------------------------------------------------
  1179.  
  1180. SOM_Scope ODBoolean  SOMLINK ODWindowIsRootWindow(ODWindow *somSelf, Environment *ev)
  1181. {
  1182.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1183.     ODWindowMethodDebug("ODWindow","IsRootWindow");
  1184.  
  1185.     return _fIsRootWindow;
  1186. }
  1187.  
  1188. //-------------------------------------------------------------------------------------
  1189. // ODWindow: ShouldSave
  1190. //
  1191. // Description
  1192. //-------------------------------------------------------------------------------------
  1193.  
  1194. SOM_Scope ODBoolean  SOMLINK ODWindowShouldSave(ODWindow *somSelf, Environment *ev)
  1195. {
  1196.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1197.     ODWindowMethodDebug("ODWindow","ShouldSave");
  1198.  
  1199.     return _fShouldSave;
  1200. }
  1201.  
  1202. //-------------------------------------------------------------------------------------
  1203. // ODWindow: SetShouldSave
  1204. //
  1205. // Description
  1206. //-------------------------------------------------------------------------------------
  1207.  
  1208. SOM_Scope void  SOMLINK ODWindowSetShouldSave(ODWindow *somSelf, Environment *ev,
  1209.         ODBoolean shouldSave)
  1210. {
  1211.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1212.     ODWindowMethodDebug("ODWindow","SetShouldSave");
  1213.  
  1214.     _fShouldSave = shouldSave;
  1215.     _fIsDirty = kODTrue;
  1216. }
  1217.  
  1218. //-------------------------------------------------------------------------------------
  1219. // ODWindow: ShouldShowLinks
  1220. //
  1221. // Description
  1222. //-------------------------------------------------------------------------------------
  1223.  
  1224. SOM_Scope ODBoolean  SOMLINK ODWindowShouldShowLinks(ODWindow *somSelf, Environment *ev)
  1225. {
  1226.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1227.     ODWindowMethodDebug("ODWindow","ShouldShowLinks");
  1228.  
  1229.     return _fShouldShowLinks;
  1230. }
  1231.  
  1232. //-------------------------------------------------------------------------------------
  1233. // ODWindow: SetShouldShowLinks
  1234. //
  1235. // Description
  1236. //-------------------------------------------------------------------------------------
  1237.  
  1238. SOM_Scope void  SOMLINK ODWindowSetShouldShowLinks(ODWindow *somSelf, Environment *ev,
  1239.         ODBoolean shouldShowLinks)
  1240. {
  1241.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1242.     ODWindowMethodDebug("ODWindow","SetShouldShowLinks");
  1243.  
  1244.     _fShouldShowLinks = shouldShowLinks;
  1245.     _fIsDirty = kODTrue;
  1246. }
  1247.  
  1248. //-------------------------------------------------------------------------------------
  1249. // ODWindow: ShouldDispose
  1250. //
  1251. // Description
  1252. //-------------------------------------------------------------------------------------
  1253.  
  1254. SOM_Scope ODBoolean  SOMLINK ODWindowShouldDispose(ODWindow *somSelf, Environment *ev)
  1255. {
  1256.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1257.     ODWindowMethodDebug("ODWindow","ShouldDispose");
  1258.  
  1259.     return _fShouldDispose;
  1260. }
  1261.  
  1262. //-------------------------------------------------------------------------------------
  1263. // ODWindow: GetFacetUnderPoint
  1264. //
  1265. // Description
  1266. //-------------------------------------------------------------------------------------
  1267.  
  1268. typedef enum { kODForDragEvent, kODForMouseEvent } FacetSearchConstraint;
  1269.  
  1270. ODFacet* GetFacetUnderPointInternal( Environment *ev, ODFacet* rootFacet,
  1271.         ODPoint* windowPoint, FacetSearchConstraint constraint );
  1272.  
  1273.  
  1274. //-------------------------------------------------------------------------------------
  1275. // ODWindow: GetFacetUnderPoint
  1276. //
  1277. // Description
  1278. //-------------------------------------------------------------------------------------
  1279.  
  1280. SOM_Scope ODFacet*  SOMLINK ODWindowGetFacetUnderPointForDrag(ODWindow *somSelf,
  1281.         Environment *ev, ODPoint* windowPoint)
  1282. {
  1283.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1284.     ODWindowMethodDebug("ODWindow","GetFacetUnderPointForDrag");
  1285.  
  1286.     ODFacet* foundFacet = kODNULL;
  1287.     
  1288.     SOM_TRY
  1289.         foundFacet = GetFacetUnderPointInternal( ev, _fRootFacet, windowPoint,
  1290.                 kODForDragEvent );
  1291.     SOM_CATCH_ALL
  1292.     SOM_ENDTRY
  1293.  
  1294.     return foundFacet;
  1295. }
  1296.  
  1297. //-------------------------------------------------------------------------------------
  1298. // ODWindow: GetFacetUnderPoint
  1299. //
  1300. // Description
  1301. //-------------------------------------------------------------------------------------
  1302.  
  1303. SOM_Scope ODFacet*  SOMLINK ODWindowGetFacetUnderPoint(ODWindow *somSelf,
  1304.         Environment *ev, ODPoint* windowPoint)
  1305. {
  1306.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1307.     ODWindowMethodDebug("ODWindow","GetFacetUnderPoint");
  1308.  
  1309.     ODFacet* foundFacet = kODNULL;
  1310.     
  1311.     SOM_TRY
  1312.         foundFacet = GetFacetUnderPointInternal( ev, _fRootFacet, windowPoint,
  1313.                 kODForMouseEvent );
  1314.     SOM_CATCH_ALL
  1315.     SOM_ENDTRY
  1316.  
  1317.     return foundFacet;
  1318. }
  1319.  
  1320. //-------------------------------------------------------------------------------------
  1321. // GetFacetUnderPointInternal
  1322. //
  1323. // Description
  1324. // Utility function for the two GetFacetUnderPoint methods above.
  1325. //-------------------------------------------------------------------------------------
  1326. ODFacet* GetFacetUnderPointInternal( Environment *ev, ODFacet* rootFacet,
  1327.         ODPoint* windowPoint, FacetSearchConstraint constraint )
  1328. {
  1329.     ODFacet* foundFacet = kODNULL;
  1330.     ODFacetIterator* t = kODNULL;        ODVolatile(t);
  1331.     ODPoint framePoint;
  1332.  
  1333.     SOM_TRY
  1334.         //!!! Should use frameshape containment to prune search
  1335.         t = rootFacet->CreateFacetIterator(ev,
  1336.                                 kODTopDown, kODBackToFront);
  1337.     
  1338.         for ( ODFacet* facet = t->First(ev);
  1339.                 t->IsNotComplete(ev);
  1340.                 facet = t->Next(ev) )
  1341.         {
  1342.             // get windowPoint in frame coords for hit-testing
  1343.             { TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
  1344.               framePoint = *windowPoint;
  1345.               winToFrame->InvertPoint(ev, &framePoint);
  1346.             }
  1347.             
  1348.             if (facet->ContainsPoint(ev, &framePoint, kODNULL))
  1349.             {
  1350.                 foundFacet = facet;
  1351.                 if (facet->GetFrame(ev)->IsFrozen(ev))
  1352.                     t->SkipChildren(ev);
  1353.                 else if ( (constraint == kODForMouseEvent) && facet->IsSelected(ev))
  1354.                 {
  1355.                     t->SkipChildren(ev);
  1356.                 }
  1357.             }
  1358.             else
  1359.                 t->SkipChildren(ev);
  1360.         }
  1361.         delete t;
  1362.  
  1363.     SOM_CATCH_ALL
  1364.  
  1365.         ODDeleteObject(t);
  1366.  
  1367.     SOM_ENDTRY
  1368.  
  1369.     return foundFacet;
  1370. }
  1371.  
  1372. //-------------------------------------------------------------------------------------
  1373. // ODWindow: IsActive
  1374. //
  1375. // Description
  1376. //-------------------------------------------------------------------------------------
  1377.  
  1378. SOM_Scope ODBoolean  SOMLINK ODWindowIsActive(ODWindow *somSelf, Environment *ev)
  1379. {
  1380.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1381.     ODWindowMethodDebug("ODWindow","IsActive");
  1382.     
  1383.     return _fIsActive && !_fInBackground;
  1384. }
  1385.  
  1386. //-------------------------------------------------------------------------------------
  1387. // ODWindow: Show
  1388. //
  1389. // Description
  1390. //-------------------------------------------------------------------------------------
  1391.  
  1392. SOM_Scope void  SOMLINK ODWindowShow(ODWindow *somSelf, Environment *ev)
  1393. {
  1394.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1395.     ODWindowMethodDebug("ODWindow","Show");
  1396.     
  1397.     SOM_TRY
  1398.  
  1399.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1400.         
  1401.         if (!somSelf->IsShown(ev))    
  1402.             _fWindowState->ShowODWindow(ev,somSelf);
  1403.         _fIsDirty = kODTrue;
  1404.  
  1405.     SOM_CATCH_ALL
  1406.     SOM_ENDTRY
  1407. }
  1408.     
  1409. //-------------------------------------------------------------------------------------
  1410. // ODWindow: Hide
  1411. //
  1412. // Description
  1413. //-------------------------------------------------------------------------------------
  1414.  
  1415. SOM_Scope void  SOMLINK ODWindowHide(ODWindow *somSelf, Environment *ev)
  1416. {
  1417.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1418.     ODWindowMethodDebug("ODWindow","Hide");
  1419.  
  1420.     SOM_TRY
  1421.  
  1422.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1423.  
  1424.         if (somSelf->IsShown(ev))
  1425.         {
  1426.             _fWindowState->HideODWindow(ev,somSelf);
  1427.             _fIsDirty = kODTrue;
  1428.         }
  1429.  
  1430.     SOM_CATCH_ALL
  1431.     SOM_ENDTRY
  1432. }
  1433.  
  1434. //-------------------------------------------------------------------------------------
  1435. // ODWindow: SuspendResume
  1436. //
  1437. // Send event to each visible window
  1438. //-------------------------------------------------------------------------------------
  1439.  
  1440. SOM_Scope void  SOMLINK ODWindowSuspendResume(ODWindow *somSelf, Environment *ev,
  1441.         ODEventData* event)
  1442. {
  1443.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1444.     ODWindowMethodDebug("ODWindow","SuspendResume");
  1445.  
  1446.  
  1447.     const short kResumeMask = 0x01;    // High byte suspend/resume event 
  1448.     ODFrame* frame = kODNULL;
  1449.     ODFacetIterator* t = kODNULL; ODVolatile(t);
  1450.  
  1451.     _fInBackground = (event->message & kResumeMask) == 0;
  1452.  
  1453.     SOM_TRY
  1454.  
  1455.         if ( _fIsActive )
  1456.         {
  1457.             if ( _fInBackground )
  1458.                 _fWindowState->DeactivateWindow( ev, _fPlatformWindow );
  1459.             else
  1460.                 _fWindowState->ActivateWindow( ev, _fPlatformWindow );
  1461.         }
  1462.  
  1463.         somSelf->PrepareCanvas(ev);
  1464.         if (somSelf->IsResizable(ev))
  1465.             ODDrawGrowIcon(_fPlatformWindow);
  1466.  
  1467.         if ( _fRootFacet != kODNULL )
  1468.         {    
  1469.             t = _fRootFacet->CreateFacetIterator(ev,
  1470.                                     kODTopDown, kODFrontToBack);
  1471.             
  1472.             for (ODFacet* facet = t->First(ev); t->IsNotComplete(ev); facet = t->Next(ev))
  1473.             {
  1474.                 if (facet)
  1475.                 {
  1476.                     TRY{
  1477.                         frame = facet->GetFrame(ev);
  1478.                         TempODPart part = frame->AcquirePart(ev); // -- TÇ tempobj'd
  1479.                         if ((ODPart*)part)
  1480.                             part->HandleEvent(ev,event, frame, facet, kODNULL);
  1481.                     }CATCH_ALL{
  1482.                         // ignore exception
  1483.                     }ENDTRY
  1484.                 }
  1485.             }
  1486.             ODDeleteObject(t);
  1487.         }
  1488.         else
  1489.         {
  1490.             WARN( "Can’t suspend/resume--This window has no root facet." );
  1491.         }
  1492.  
  1493.     SOM_CATCH_ALL
  1494.     
  1495.         ODDeleteObject(t);
  1496.         
  1497.     SOM_ENDTRY
  1498. }
  1499.  
  1500. //-------------------------------------------------------------------------------------
  1501. // ODWindow: Activate
  1502. //
  1503. // Description
  1504. //-------------------------------------------------------------------------------------
  1505.  
  1506. SOM_Scope void  SOMLINK ODWindowActivate(ODWindow *somSelf, Environment *ev)
  1507. {
  1508.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1509.     ODWindowMethodDebug("ODWindow","Activate");
  1510.  
  1511.     SOM_TRY
  1512.  
  1513.         if ( !_fIsActive )
  1514.         {
  1515.             _fIsActive = kODTrue;
  1516.  
  1517.             // Defer actual activation until process is resumed
  1518.             if ( !_fInBackground )
  1519.                 _fWindowState->ActivateWindow( ev, _fPlatformWindow );
  1520.         }
  1521.  
  1522.     SOM_CATCH_ALL
  1523.     SOM_ENDTRY
  1524. }
  1525.  
  1526. //-------------------------------------------------------------------------------------
  1527. // ODWindow: Deactivate
  1528. //
  1529. // Description
  1530. //-------------------------------------------------------------------------------------
  1531.  
  1532. SOM_Scope void  SOMLINK ODWindowDeactivate(ODWindow *somSelf, Environment *ev)
  1533. {
  1534.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1535.     ODWindowMethodDebug("ODWindow","Deactivate");
  1536.  
  1537.     SOM_TRY
  1538.     
  1539.         if ( _fIsActive )
  1540.         {
  1541.             _fIsActive = kODFalse;
  1542.  
  1543.             // If process is suspended, window was already deactivated
  1544.             if ( !_fInBackground )
  1545.                 _fWindowState->DeactivateWindow( ev, _fPlatformWindow );
  1546.         }
  1547.  
  1548.     SOM_CATCH_ALL
  1549.     SOM_ENDTRY
  1550. }
  1551.  
  1552. //-------------------------------------------------------------------------------------
  1553. // ODWindow: Drag
  1554. //
  1555. // Description
  1556. //-------------------------------------------------------------------------------------
  1557.  
  1558. SOM_Scope void  SOMLINK ODWindowDrag(ODWindow *somSelf, Environment *ev,
  1559.         Point* startPoint,
  1560.         Rect* draggingBounds)
  1561. {
  1562.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1563.     ODWindowMethodDebug("ODWindow","Drag");
  1564.  
  1565.     SOM_TRY
  1566.  
  1567.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1568.         
  1569.         _fWindowState->DragODWindow(ev,somSelf, startPoint, draggingBounds);
  1570.  
  1571.     SOM_CATCH_ALL
  1572.     SOM_ENDTRY
  1573. }
  1574.  
  1575. //-------------------------------------------------------------------------------------
  1576. // ODWindow: Select
  1577. //
  1578. // Description
  1579. //-------------------------------------------------------------------------------------
  1580.  
  1581. SOM_Scope void  SOMLINK ODWindowSelect(ODWindow *somSelf, Environment *ev)
  1582. {
  1583.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1584.     ODWindowMethodDebug("ODWindow","Select");
  1585.  
  1586.     SOM_TRY
  1587.  
  1588.         if (_fInBackground)
  1589.         {
  1590.             ProcessSerialNumber current;
  1591.             OSErr    err = GetCurrentProcess(¤t);
  1592.             if (err == noErr)
  1593.                 SetFrontProcess(¤t);
  1594.         }    
  1595.         _fWindowState->SelectODWindow(ev,somSelf);
  1596.  
  1597.     SOM_CATCH_ALL
  1598.     SOM_ENDTRY
  1599. }
  1600.  
  1601. //-------------------------------------------------------------------------------------
  1602. // ODWindow: IsShown
  1603. //
  1604. // Description
  1605. //-------------------------------------------------------------------------------------
  1606.  
  1607. SOM_Scope ODBoolean  SOMLINK ODWindowIsShown(ODWindow *somSelf, Environment *ev)
  1608. {
  1609.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1610.     ODWindowMethodDebug("ODWindow","IsShown");
  1611.     
  1612.     ODBoolean isShown = kODFalse;
  1613.     
  1614.     SOM_TRY
  1615.  
  1616.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1617.         
  1618.         isShown = ((WindowRecord*)_fPlatformWindow)->visible;
  1619.  
  1620.     SOM_CATCH_ALL
  1621.     SOM_ENDTRY
  1622.     
  1623.     return isShown;
  1624. }
  1625.  
  1626. //-------------------------------------------------------------------------------------
  1627. // Protected methods
  1628. //
  1629. // Description
  1630. //-------------------------------------------------------------------------------------
  1631.  
  1632. SOM_Scope ODBoolean  SOMLINK ODWindowHasCloseBox(ODWindow *somSelf, Environment *ev)
  1633. {
  1634.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1635.     ODWindowMethodDebug("ODWindow","HasCloseBox");
  1636.  
  1637.     ODBoolean hasCloseBox = kODFalse;
  1638.     
  1639.     SOM_TRY
  1640.  
  1641.         ASSERT(_fPlatformWindow != kODNULL,kODErrInvalidPlatformWindow);
  1642.         hasCloseBox =     ((WindowRecord*)_fPlatformWindow)->goAwayFlag;
  1643.  
  1644.     SOM_CATCH_ALL
  1645.     SOM_ENDTRY
  1646.     
  1647.     return hasCloseBox;
  1648. }
  1649.     
  1650. SOM_Scope ODBoolean  SOMLINK ODWindowHasZoomBox(ODWindow *somSelf, Environment *ev)
  1651.  
  1652. {
  1653.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1654.     ODWindowMethodDebug("ODWindow","HasZoomBox");
  1655.  
  1656.     ODBoolean hasZoomBox = kODFalse;
  1657.     
  1658.     SOM_TRY
  1659.     
  1660.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1661.         hasZoomBox = ((WindowRecord*)_fPlatformWindow)->spareFlag;
  1662.  
  1663.     SOM_CATCH_ALL
  1664.     SOM_ENDTRY
  1665.     
  1666.     return hasZoomBox;
  1667. }
  1668.  
  1669. SOM_Scope ODBoolean  SOMLINK ODWindowHasGrowBox(ODWindow *somSelf, Environment *ev)
  1670. {
  1671.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1672.     ODWindowMethodDebug("ODWindow","HasGrowBox");
  1673.  
  1674.     ODBoolean hasGrowBox = kODFalse;
  1675.     
  1676.     SOM_TRY
  1677.  
  1678.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1679.         hasGrowBox = somSelf->IsResizable(ev); 
  1680.  
  1681.     SOM_CATCH_ALL
  1682.     SOM_ENDTRY
  1683.     
  1684.     return hasGrowBox;
  1685. }
  1686.  
  1687. SOM_Scope ODSShort  SOMLINK ODWindowGetProcID(ODWindow *somSelf, Environment *ev)
  1688. {
  1689.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1690.     ODWindowMethodDebug("ODWindow","GetProcID");
  1691.     
  1692.     short theID = 0; 
  1693.     ResType theType;
  1694.     Str255 theName;
  1695.  
  1696.     SOM_TRY
  1697.     
  1698.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1699.  
  1700.         GetResInfo(((WindowPeek)_fPlatformWindow)->windowDefProc, &theID, &theType, theName);
  1701.         short theVariant = GetWVariant(_fPlatformWindow);
  1702.         theID = theID*16 + theVariant;
  1703.         // return GetWVariant(_fPlatformWindow);
  1704.         
  1705.     SOM_CATCH_ALL
  1706.     SOM_ENDTRY
  1707.     
  1708.     return theID;
  1709.     
  1710. }
  1711.  
  1712. SOM_Scope void  SOMLINK ODWindowGetWindowBounds(ODWindow *somSelf, Environment *ev,
  1713.         Rect* bounds)
  1714. {
  1715.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1716.     ODWindowMethodDebug("ODWindow","GetWindowBounds");
  1717.     
  1718.     SOM_TRY
  1719.  
  1720.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1721.  
  1722.     // This old code doesn't work when the window is shaded by WindowShade:
  1723.         
  1724.         //ODRgnHandle contRgn;
  1725.         
  1726.         //contRgn = ((WindowRecord*)_fPlatformWindow)->contRgn;
  1727.         //*bounds = (**contRgn).rgnBBox;
  1728.     
  1729.     // This new code works with WindowShade:
  1730.         
  1731.         const ODUShort kColorPort = 0xC000;
  1732.          ODBoolean isCGrafPort =
  1733.              (((CGrafPtr)_fPlatformWindow)->portVersion & kColorPort ) == kColorPort;
  1734.  
  1735.         if ( isCGrafPort )
  1736.         {
  1737.             CGrafPtr port = (CGrafPtr)_fPlatformWindow;
  1738.             bounds->left   = port->portRect.left - (**(port->portPixMap)).bounds.left;
  1739.             bounds->top    = port->portRect.top - (**(port->portPixMap)).bounds.top;
  1740.             bounds->right  = bounds->left - port->portRect.left + port->portRect.right;
  1741.             bounds->bottom = bounds->top - port->portRect.top + port->portRect.bottom;
  1742.         }
  1743.         else // It's just a GrafPort
  1744.         {
  1745.             GrafPtr port = (GrafPtr)_fPlatformWindow;
  1746.             bounds->left   = port->portRect.left - port->portBits.bounds.left;
  1747.             bounds->top    = port->portRect.top - port->portBits.bounds.top;
  1748.             bounds->right  = bounds->left - port->portRect.left + port->portRect.right;
  1749.             bounds->bottom = bounds->top - port->portRect.top + port->portRect.bottom;
  1750.         }
  1751.         
  1752.     SOM_CATCH_ALL
  1753.     SOM_ENDTRY    
  1754. }
  1755.  
  1756. SOM_Scope ODSLong  SOMLINK ODWindowGetRefCon(ODWindow *somSelf, Environment *ev)
  1757. {
  1758.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1759.     ODWindowMethodDebug("ODWindow","GetRefCon");
  1760.     
  1761.     ODSLong refCon = 0;
  1762.     
  1763.     SOM_TRY
  1764.  
  1765.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1766.         refCon = ((WindowRecord*)_fPlatformWindow)->refCon;
  1767.  
  1768.     SOM_CATCH_ALL
  1769.     SOM_ENDTRY    
  1770.     
  1771.     return refCon;
  1772. }
  1773.  
  1774. //-------------------------------------------------------------------------------------
  1775. // ODWindow: SetWindowTitle
  1776. //
  1777. // Description
  1778. //-------------------------------------------------------------------------------------
  1779.  
  1780. SOM_Scope void  SOMLINK ODWindowSetWindowTitle(ODWindow *somSelf, Environment *ev,
  1781.         char* title)
  1782. {
  1783.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1784.     ODWindowMethodDebug("ODWindow","SetWindowTitle");
  1785.     
  1786.     Str255 titleCopy;
  1787.     
  1788.     strcpy( (char*) &(titleCopy[1]), title);
  1789.     titleCopy[0] = strlen(title);
  1790.     
  1791.     SOM_TRY
  1792.  
  1793.         SetWTitle(_fPlatformWindow, titleCopy);
  1794.         _fIsDirty = kODTrue;
  1795.  
  1796.     SOM_CATCH_ALL
  1797.     SOM_ENDTRY    
  1798. }
  1799.  
  1800. //-------------------------------------------------------------------------------------
  1801. // ODWindow: SetWasVisible
  1802. //
  1803. // Description
  1804. //-------------------------------------------------------------------------------------
  1805.  
  1806. SOM_Scope void  SOMLINK ODWindowSetWasVisible(ODWindow *somSelf, Environment *ev,
  1807.         ODBoolean wasVisible)
  1808. {
  1809.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1810.     ODWindowMethodDebug("ODWindow","SetWasVisible");
  1811.  
  1812.     _fWasVisible = wasVisible;
  1813.     _fIsDirty = kODTrue;
  1814. }
  1815.  
  1816. //-------------------------------------------------------------------------------------
  1817. // ODWindow: GetWasVisible
  1818. //
  1819. // Description
  1820. //-------------------------------------------------------------------------------------
  1821.  
  1822. SOM_Scope ODBoolean  SOMLINK ODWindowGetWasVisible(ODWindow *somSelf, Environment *ev)
  1823. {
  1824.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1825.     ODWindowMethodDebug("ODWindow","GetWasVisible");
  1826.  
  1827.     return _fWasVisible;
  1828. }
  1829.  
  1830. //-------------------------------------------------------------------------------------
  1831. // ODWindow: Externalize
  1832. //
  1833. // Description
  1834. //-------------------------------------------------------------------------------------
  1835.  
  1836. SOM_Scope void  SOMLINK ODWindowExternalize(ODWindow *somSelf, Environment *ev)
  1837. {
  1838.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1839.     ODWindowMethodDebug("ODWindow","Externalize");
  1840.  
  1841.     // #1246478 Removing fIsDirty optimization, because clients can call GetPlatformWindow
  1842.     // and change things. 
  1843.     //if ( !_fIsDirty )
  1844.     //    return;
  1845.         
  1846.     SOM_TRY
  1847.  
  1848.     // Should Title be an ODIText?
  1849.         
  1850.         ODStorageUnit* su = _fStorageUnit;
  1851.         
  1852.         // No need to do these ASSERTs because the StdTypIO routines make sure
  1853.         // the appropriate property and value exist. -TÇ
  1854.         /*
  1855.         ASSERT(su->Exists(ev,kODPropWindowRect, kODRect, 0), kODErrInvalidWindow);        
  1856.         ASSERT(su->Exists(ev,kODPropWindowTitle, kODMacIText, 0), kODErrInvalidWindow);
  1857.         ASSERT(su->Exists(ev,kODPropWindowProcID, kODSShort, 0), kODErrInvalidWindow);
  1858.         ASSERT(su->Exists(ev,kODPropWindowIsVisible, kODBoolean, 0), kODErrInvalidWindow);
  1859.         ASSERT(su->Exists(ev,kODPropWindowHasCloseBox, kODBoolean, 0), kODErrInvalidWindow);
  1860.         ASSERT(su->Exists(ev,kODPropWindowHasZoomBox, kODBoolean, 0), kODErrInvalidWindow);
  1861.         ASSERT(su->Exists(ev,kODPropWindowIsResizable, kODBoolean, 0), kODErrInvalidWindow);
  1862.         ASSERT(su->Exists(ev,kODPropWindowIsRootWindow, kODBoolean, 0), kODErrInvalidWindow);
  1863.         ASSERT(su->Exists(ev,kODPropWindowIsFloating, kODBoolean, 0), kODErrInvalidWindow);
  1864.         ASSERT(su->Exists(ev,kODPropWindowRefCon, kODSLong, 0), kODErrInvalidWindow);
  1865.         ASSERT(su->Exists(ev,kODPropRootFrame, kODStrongStorageUnitRef, 0), kODErrInvalidWindow);
  1866.         //ASSERT(su->Exists(ev,kODPropSourceFrame, kODStrongStorageUnitRef, 0), kODErrInvalidWindow);
  1867.         ASSERT(su->Exists(ev,kODPropShouldShowLinks, kODBoolean, 0), kODErrInvalidWindow);
  1868.         */
  1869.         
  1870.         // Externalize Window Manager properties
  1871.     
  1872.         // Externalize the bounds as a standard ODRect
  1873.     
  1874.         Rect r;
  1875.         somSelf->GetWindowBounds(ev,&r);
  1876.         ODRect odRect(r);
  1877.         ODSetRectProp(ev, su, kODPropWindowRect, kODRect, &odRect);
  1878.         
  1879.         // Externalize title as an IText
  1880.         
  1881.         Str255 title;
  1882.         GetWTitle(_fPlatformWindow, title);
  1883.         
  1884.         ODScriptCode script = FontToScript(GetAppFont());
  1885.         ODLangCode lang = GetScriptVariable(script, smScriptLang);
  1886.  
  1887.         ODIText* iText = CreateITextPString(script, lang, &title[0]);
  1888.         ODSetITextProp(ev, su, kODPropWindowTitle, kODMacIText, iText);
  1889.         DisposeIText(iText);
  1890.     
  1891.         ODSetSShortProp(ev, su, kODPropWindowProcID, kODSShort, somSelf->GetProcID(ev));
  1892.         ODSetBooleanProp(ev, su, kODPropWindowIsVisible, kODBoolean, somSelf->IsShown(ev));
  1893.         ODSetBooleanProp(ev, su, kODPropWindowHasCloseBox, kODBoolean,  somSelf->HasCloseBox(ev));
  1894.         ODSetBooleanProp(ev, su, kODPropWindowHasZoomBox, kODBoolean,  somSelf->HasZoomBox(ev));
  1895.         ODSetULongProp(ev, su, kODPropWindowRefCon, kODSLong, somSelf->GetRefCon(ev));
  1896.         
  1897.         // Other properties
  1898.         
  1899.         ODSetBooleanProp(ev, su, kODPropWindowIsResizable, kODBoolean,   somSelf->IsResizable(ev));
  1900.         ODSetBooleanProp(ev, su, kODPropWindowIsFloating, kODBoolean, somSelf->IsFloating(ev));
  1901.         ODSetBooleanProp(ev, su, kODPropWindowIsRootWindow, kODBoolean, somSelf->IsRootWindow(ev));
  1902.     
  1903.         ODSetBooleanProp(ev, su, kODPropShouldShowLinks, kODBoolean, somSelf->ShouldShowLinks(ev)); 
  1904.     
  1905.         // root frame
  1906.     
  1907.         ODSetStrongSURefProp(ev, su, kODPropRootFrame, kODStrongStorageUnitRef, _fRootFrame->GetStorageUnit(ev)->GetID(ev));
  1908.     
  1909.         // Source Frame (this property is only written if the value is non-NULL)  
  1910.             
  1911.         if (_fSourceFrame)
  1912.         {            
  1913.             ODSetStrongSURefProp(ev, su, kODPropSourceFrame, kODStrongStorageUnitRef, 
  1914.                             _fSourceFrame->GetStorageUnit(ev)->GetID(ev));
  1915.         }
  1916.         else if (ODSUExistsThenFocus(ev, su ,kODPropSourceFrame, kODStrongStorageUnitRef))
  1917.         {
  1918.             su->Remove(ev);
  1919.         }
  1920.         
  1921.         // Annotate the root frame with the window properties
  1922.         ODStorageUnit* frameSU = _fRootFrame->GetStorageUnit(ev);
  1923.         ODSetStrongSURefProp(ev, frameSU, kODPropWindowProperties, kODStrongStorageUnitRef, 
  1924.                         su->GetID(ev));
  1925.     
  1926.         _fIsDirty = kODFalse;
  1927.         
  1928.     SOM_CATCH_ALL
  1929.     SOM_ENDTRY
  1930. }
  1931.  
  1932. //-------------------------------------------------------------------------------------
  1933. // ODWindow: GetID
  1934. //
  1935. // Description
  1936. //-------------------------------------------------------------------------------------
  1937.  
  1938. SOM_Scope ODID  SOMLINK ODWindowGetID(ODWindow *somSelf, Environment *ev)
  1939. {
  1940.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1941.     ODWindowMethodDebug("ODWindow","GetID");
  1942.  
  1943.     return _fID;
  1944. }
  1945.  
  1946. //-------------------------------------------------------------------------------------
  1947. // ODWindow: SetID
  1948. //
  1949. // Description
  1950. //-------------------------------------------------------------------------------------
  1951.  
  1952. SOM_Scope void  SOMLINK ODWindowSetID(ODWindow *somSelf, Environment *ev,
  1953.         ODID windowID)
  1954. {
  1955.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1956.     ODWindowMethodDebug("ODWindow","SetID");
  1957.  
  1958.     _fID = windowID;
  1959. }
  1960.  
  1961. //-------------------------------------------------------------------------------------
  1962. // ODWindow: AcquireStorageUnit
  1963. //
  1964. // Description
  1965. //-------------------------------------------------------------------------------------
  1966.  
  1967. SOM_Scope ODStorageUnit*  SOMLINK ODWindowGetStorageUnit(ODWindow *somSelf, Environment *ev)
  1968. {
  1969.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1970.     ODWindowMethodDebug("ODWindow","GetStorageUnit");
  1971.     
  1972.     SOM_TRY
  1973.     
  1974.         if (_fStorageUnit != kODNULL)
  1975.             _fStorageUnit->Internalize(ev);
  1976.  
  1977.     SOM_CATCH_ALL
  1978.     SOM_ENDTRY
  1979.  
  1980.     return _fStorageUnit;
  1981. }
  1982.  
  1983. //-------------------------------------------------------------------------------------
  1984. // ODWindow: SetStorageUnit
  1985. //
  1986. // Description
  1987. //-------------------------------------------------------------------------------------
  1988.  
  1989. SOM_Scope void  SOMLINK ODWindowSetStorageUnit(ODWindow *somSelf, Environment *ev, ODStorageUnit* su)
  1990. {
  1991.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1992.     ODWindowMethodDebug("ODWindow","SetStorageUnit");
  1993.     
  1994.     SOM_TRY
  1995.  
  1996.         _fStorageUnit = su;
  1997.         su->Acquire(ev);
  1998.         
  1999.         // These below calls are unnecessary because the StdTypIO routines make sure
  2000.         // the appropriate property and value exist. -TÇ
  2001.         /*
  2002.         ODSUAddPropValue(ev, kODPropWindowRect, kODRect);
  2003.         ODSUAddPropValue(ev, kODPropWindowTitle, kODMacIText);
  2004.         ODSUAddPropValue(ev, kODPropWindowProcID, kODSShort);
  2005.         ODSUAddPropValue(ev, kODPropWindowIsVisible, kODBoolean);
  2006.         ODSUAddPropValue(ev, kODPropWindowHasCloseBox, kODBoolean);
  2007.         ODSUAddPropValue(ev, kODPropWindowHasZoomBox, kODBoolean);
  2008.         ODSUAddPropValue(ev, kODPropWindowIsResizable, kODBoolean);
  2009.         ODSUAddPropValue(ev, kODPropWindowIsRootWindow, kODBoolean);
  2010.         ODSUAddPropValue(ev, kODPropWindowIsFloating, kODBoolean);
  2011.         ODSUAddPropValue(ev, kODPropWindowRefCon, kODSLong);
  2012.         ODSUAddPropValue(ev, kODPropRootFrame, kODStrongStorageUnitRef);
  2013.         ODSUAddPropValue(ev, kODPropShouldShowLinks, kODBoolean);
  2014.         */
  2015.         
  2016.         _fIsDirty = kODTrue;
  2017.  
  2018.     SOM_CATCH_ALL
  2019.     SOM_ENDTRY
  2020. }
  2021.  
  2022. //-------------------------------------------------------------------------------------
  2023. // ODWindow: GetDraft
  2024. //
  2025. // Description
  2026. //-------------------------------------------------------------------------------------
  2027.  
  2028. SOM_Scope ODDraft*  SOMLINK ODWindowGetDraft(ODWindow *somSelf, Environment *ev)
  2029. {
  2030.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2031.     ODWindowMethodDebug("ODWindow","GetDraft");
  2032.  
  2033.     return _fDraft;
  2034. }
  2035.  
  2036. //-------------------------------------------------------------------------------------
  2037. // ODWindow: GetWindowPoint
  2038. //
  2039. // Description
  2040. //-------------------------------------------------------------------------------------
  2041.  
  2042. SOM_Scope void SOMLINK ODWindowGetWindowPoint(ODWindow *somSelf, Environment *ev,
  2043.         Point* globalPoint, ODPoint* windowPoint)
  2044. {
  2045.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2046.     ODWindowMethodDebug("ODWindow","GetWindowPoint");
  2047.     
  2048.     Point localCopy = *globalPoint;
  2049.     
  2050.     GrafPtr curPort;
  2051.     GetPort(&curPort);
  2052.     SetPort(_fPlatformWindow);
  2053.     SetOrigin(0,0);
  2054.     GlobalToLocal(&localCopy);
  2055.     SetPort(curPort);
  2056.     *windowPoint = (ODPoint)localCopy;
  2057. }
  2058.